﻿var str_uiFormHtml = '<form  id="uiform"><table class="grid2"  cellspacing=1 width=100%>';
str_uiFormHtml += '<tr><td>用户：</td><td><input  id="txtUserName"  name="UserName" required="true" type="text" class="txt03" /></td></tr>';
str_uiFormHtml += '<tr><td>发生日期：</td><td><input id="txtCreateOn" name="CreateOn"  required="true" type="text" class="txt03" /></td></tr>';
str_uiFormHtml += '<tr><td>错误信息：</td><td><textarea  id="txtFormattedMessage" style="width:500px; height:330px;" name="FormattedMessage" class="txt03" /></td></tr>';
str_uiFormHtml += '</table></form>';

$(function () {
    autoResize({ dataGrid: '#list', callback: initList });
    $('#btnRefresh').click(reloadList);
});

var reloadList = function () {
    $("#list").trigger("reloadGrid", [{ page: 1}]);
}

var initList = function (size) {
    $('#list').jqGrid({
        url: "handler/ExceptionAdminHandler.ashx?action=getlist",
        datatype: "json",
        autowidth: true,
        height: size.height,
        width: size.width,
        colNames: ["发生日期", "异常信息来源", "异常信息", "异常信息描述", "创建者", "Id" ],
        colModel: [
                    { name: "CreateBy", index: "CreateBy", align: "center", width: 70 },
                    { name: "CreateOn", index: "CreateOn", align: "center", width: 80 },
                    { name: "ThreadName", index: "ThreadName", align: "left", width: 120 },
                    { name: "Message", index: "Message", align: "left", width: 150 },                    
                    { name: "FormattedMessage", index: "FormattedMessage", align: "left",hidden: true },
                    { name: "Id", index: "Id", hidden: true }                   
                ],
        viewrecords: true,
        rowNum: 20,
        rowList: [10, 20, 30],
        sortname: "CreateOn",
        sortorder: "DESC",
        jsonReader: { repeatitems: false },
        pager: "#pager",
        caption: "<span class='icon icon-list'>系统异常列表</span>",
        hidegrid: false,
        ondblClickRow: function (rowid) {
            var exceptionObj = jQuery('#list').jqGrid('getRowData', rowid)
            showExceptionInfo(exceptionObj);
        }, multiselect: true
    });
}

var showExceptionInfo = function (oExceptionInfo) {
    //弹窗
    top.$('#w').hWindow({ html: str_uiFormHtml, width: 630, height: 510, title: '系统异常详细信息', iconCls: 'icon-list', submit: function () { top.$('#w').window('close'); } });
    //初始化相关数据
    top.$('#txtUserName').val(oExceptionInfo.CreateBy);
    top.$('#txtCreateOn').val(oExceptionInfo.CreateOn);
    top.$('#txtFormattedMessage').val(oExceptionInfo.FormattedMessage);
}